<template>
	<view>
		<!-- 选择收货地址的盒子 -->
		<view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
			<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress">请选择收货地址+</button>
		</view>

		<!-- 渲染收货信息的盒子 -->
		<view class="address-info-box" v-else @click="chooseAddress">
			<view class="address-top">
				<view class="address-people">收货人:<text user-select>{{ address.userName }}</text></view>
				<view class="address-phone">
					<view>电话: <text user-select>{{ address.telNumber }}</text></view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="address-buttom">
				<view class="address-left">收货地址:</view>
				<view class="address-city"><text user-select>{{ city }}</text></view>
			</view>
		</view>

		<!-- 底部的边框线 -->
		<image src="/static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex'
	export default {
		name: "my-address",
		data() {
			return {};
		},
		methods: {
			...mapMutations('m_user', ['updateAddress']),
			// 选择收货地址
			async chooseAddress() {
				const res = await uni.chooseAddress()
				// 点击确定
				if (res[1]) {
					// 将地址存储到仓库中
					this.updateAddress(res[1])
				}
			}
		},
		computed: {
			...mapState('m_user', ['address']),
			...mapGetters('m_user', ['city']),
		},
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	text {
		margin-left: 2px;
	}

	// 底部边框线的样式
	.address-border {
		width: 100%;
		height: 5px;
		display: block;
	}

	// 收货地址按钮
	.address-choose-box {
		height: 90px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	// 渲染收货信息的盒子
	.address-info-box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.address-top {
			display: flex;
			justify-content: space-between;
			padding: 4px;

			.address-people {
				font-size: 14px;
			}

			.address-phone {
				display: flex;
				font-size: 14px;

				text {
					font-size: 13px;
				}
			}
		}

		.address-buttom {
			padding: 4px;
			margin-bottom: 8px;
			display: flex;

			.address-left {
				font-size: 16px;
				white-space: nowrap;
			}

			.address-city {
				font-size: 14px;
				margin-left: 5px;
			}
		}
	}
</style>